package cn.demoncat.web;

import cn.demoncat.util.kuaidi100.Kuaidi100Util;
import cn.demoncat.util.web.annotation.ApiControllerMapping;
import cn.demoncat.util.web.annotation.PostJsonMapping;
import com.kuaidi100.sdk.response.SubscribeResp;
import org.springframework.web.bind.annotation.PathVariable;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 快递100通知处理
 *
 * @author 延晓磊
 * @since 2021年04月06日
 */
@ApiControllerMapping("/kuaidi100")
public class Kuaidi100Api {

    @Resource
    private Kuaidi100Util kuaidi100Util;

    /**
     * 通知处理 - 订阅物流轨迹
     *
     * @param request
     *
     * @author 延晓磊
     * @since 2021年04月06日
     */
    @PostJsonMapping("/track/{id}")
    public SubscribeResp trackCallback(@PathVariable("id") String id, HttpServletRequest request){
        return kuaidi100Util.subscribeTrackCallback(request, resp -> System.out.println(id + " > " + resp));
    }

    /**
     * 通知处理 - 订阅物流地图
     *
     * @param request
     *
     * @author 延晓磊
     * @since 2021年04月06日
     */
    @PostJsonMapping("/map-track/{id}")
    public SubscribeResp mapTrackCallback(@PathVariable("id") String id, HttpServletRequest request){
        return kuaidi100Util.subscribeMapTrackCallback(request, resp -> System.out.println(id + " > " + resp));
    }
}
